<%@ page language="java" pageEncoding="UTF-8" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<%@include file="/view/resource.jsp" %>
	<link rel="stylesheet" type="text/css" href="${ctx}/css/base.css">
	<link href="${ctx}/css/FormTable.css" rel="stylesheet" type="text/css"/>
</head>
<body>

<form id="entityForm" name="entityForm"
      action='${ctx}/alarmConfig/config' method="POST">
	<table width="100%" class="TableBlock">
		<tbody>
		<tr>
			<td colspan="6" style="font-weight: bold; background: #EFEFEF;" height="25">
				<a href="#" id="btnModify" class="topjui-menubutton" data-options="iconCls:'fa fa-save',
				   btnCls:'topjui-btn'" style="margin-top: 2px;">保存修改</a>
				<span class="MessageFromServer" id="message">${message}</span>
			</td>
		</tr>
		<tr class="TableHeader">
			<TD>报警代码</TD>
			<TD>报警类型</TD>
			<TD>报警来源</TD>
			<TD style="display:none"><input type="checkbox" id="cbCheckAllAlarm"    <c:if test="${cbCheckAllAlarm}">
				checked
			</c:if> />启用报警
			</TD>
			<TD><input type="checkbox" id="cbCheckAllSound"  <c:if test="${cbCheckAllSound}">
				checked
			</c:if> />报警声音
			</TD>
			<TD><input type="checkbox" id="cbCheckAllPopup"  <c:if test="${cbCheckAllPopup}">
				checked
			</c:if> />报警弹窗
			</TD>
		</tr>
		<c:forEach items="${alarmConfigs}" var="item">
		<tr>
			<td>${item.alarmType}</td>
			<td>${item.name}</td>
			<td>
				<c:if test="${item.alarmSource =='terminal'}"> 终端报警 </c:if>
				<c:if test="${item.alarmSource =='platform'}"> 平台报警 </c:if>
			</td>
			<td style="display:none"><input type="checkbox" id="alarmConfig_${item.id}" name="alarmEnable"
			                                value="${item.id}"
					<c:if test="${item.enabled}">
						checked
					</c:if>
			/>
			</td>
			<td><input type="checkbox" id="alarmConfig_${item.id}"
			           name="alarmSoundEnable"
			           value="${item.id}"
					<c:if test="${item.soundEnabled}">
						checked
					</c:if>
			/>
			</td>
			<td><input type="checkbox" id="alarmConfig_${item.id}"
			           name="alarmPopupEnable"
			           value="${item.id}"
					<c:if test="${item.popupEnabled}">
						checked
					</c:if>
			/>
			</td>
		</tr>
		</c:forEach>
	</table>
</form>
<script type="text/javascript">

	$().ready(function () {
		$("#cbCheckAllAlarm").click(function () {
			if ($(this).prop("checked")) {
				$('input[name="alarmEnable"]').prop("checked", true);
			} else {
				$('input[name="alarmEnable"]').prop("checked", false);
			}

			//$('input[name="alarmEnable"]').attr("checked", this.checked);
		});
		$("#cbCheckAllSound").click(function () {
			if ($(this).prop("checked")) {
				$('input[name="alarmSoundEnable"]').prop("checked", true);
			} else {
				$('input[name="alarmSoundEnable"]').prop("checked", false);
			}
			//$('input[name="alarmSoundEnable"]').attr("checked", this.checked);
		});

		$("#cbCheckAllPopup").click(function () {
			if ($(this).prop("checked")) {
				$('input[name="alarmPopupEnable"]').prop("checked", true);
			} else {
				$('input[name="alarmPopupEnable"]').prop("checked", false);
			}
			//$('input[name="alarmPopupEnable"]').attr("checked", this.checked);
		});

		$("#btnModify").click(function () {
			$('#entityForm').submit();
			return false;
		});


		$("input[name='alarmEnable']").change(function () {
			if ($("input[name='alarmEnable']").not("input:checked").size() <= 0) {
				//如果其它的复选框全部被勾选了，那么全选勾中
				$('#cbCheckAllAlarm').prop('checked', true);
			} else {
				$('#cbCheckAllAlarm').prop('checked', false);
			}
		});

		$("input[name='alarmSoundEnable']").change(function () {
			if ($("input[name='alarmSoundEnable']").not("input:checked").size() <= 0) {
				//如果其它的复选框全部被勾选了，那么全选勾中
				$('#cbCheckAllSound').prop('checked', true);
			} else {
				$('#cbCheckAllSound').prop('checked', false);
			}
		});

		$("input[name='alarmPopupEnable']").change(function () {
			if ($("input[name='alarmPopupEnable']").not("input:checked").size() <= 0) {
				//如果其它的复选框全部被勾选了，那么全选勾中
				$('#cbCheckAllPopup').prop('checked', true);
			} else {
				$('#cbCheckAllPopup').prop('checked', false);
			}
		});
	});
</script>
</body>
</html>
